home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / AMOSList / AMOSLIST.0897 / 000204_amos-request@svcs1.digex.net_Tue Aug 12 06:18:18 1997.msg < prev    next >
Text File  |  1997-09-09  |  4KB  |  93 lines

  1. Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
  2.     by mail1.access.digex.net (8.8.5/8.8.5) with ESMTP id GAA21818
  3.     for <mcox@access.digex.net>; Tue, 12 Aug 1997 06:18:16 -0400 (EDT)
  4. Received: (from daemon@localhost)
  5.     by svcs1.digex.net (8.8.5/8.8.5) id FAA03575
  6.     for amos-out; Tue, 12 Aug 1997 05:01:19 -0400 (EDT)
  7. Received: from mail3.access.digex.net (mail3.access.digex.net [205.197.247.4])
  8.     by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id FAA03572
  9.     for <amos-list@svcs1.digex.net>; Tue, 12 Aug 1997 05:01:18 -0400 (EDT)
  10. Received: from MCSDEV.MCS.CO.UK (SYSTEM@mcsdev.mcs.co.uk [193.32.50.112])
  11.     by mail3.access.digex.net (8.8.5/8.8.5) with SMTP id FAA22593
  12.     for <amos-list@digex.net>; Tue, 12 Aug 1997 05:01:02 -0400 (EDT)
  13. Date:     Tue, 12 Aug 1997 10:01 GMT
  14. From: "SIMONC%MARS.decnet"@mcs.co.uk (Simon Champion - simonc@mcs.co.uk)
  15. Message-Id: <009B8A8F1C46A560.2F22@mcs.co.uk>
  16. To: amos-list@digex.net
  17. Subject:  Re: Why is Amos SLower than C/C++
  18. X-VMS-To: MCSDEV::SMTP%"amos-list@digex.net"
  19. Status: O
  20. X-Status: 
  21.  
  22. Subj:    Why is Amos SLower than C/C++
  23.  
  24. Scott Matott wrote:
  25.  
  26.  >    Quick Question, why is complied AMos Code slower than compiled
  27.  >C/C++ code?  Maybe it's not.  I could see why Assembler would be quicker
  28.  >but why C, is it because better faster libraries are available? Or is it
  29.  >that C compilers are better optimisers? Or is C jsut faster doing some
  30.  >stuff because you can declare you variable size (ie work with Char's
  31.  >instead of Long's)  Well I was jsut wondering if anybody out there knows
  32.  >anything about this as I might go buy a C compiler to write my Caster
  33.  >since no matter what I do it seems slow in Amos.
  34.  
  35. The basic reason why Amos is slower than C is "Basic".
  36.  
  37. {lecture mode=on}
  38.  
  39. Basic is a higher level language than C. Translated into English, this
  40. means that the code is easier for a human to understand - and therefore
  41. harder for a computer to understand - than C code.
  42. When you compile the code, a line of C code is translated into fewer machine
  43. code instructions than a similar Basic instruction.
  44.  
  45. Let me think of an example......
  46.  
  47. Consider a simple loop:
  48.    Basic (ie Amos)               C
  49.  
  50.    For X=1 to 10              while(x=1,x++,x>=10) {
  51.       Print X                    printf("%d",x)
  52.    Next                       }
  53.  
  54. (You'll excuse any dumb mistakes - I've not done any C code for a while :-)
  55. but it's good enough for the example)
  56.  
  57. These two chunks of code do the same thing (roughly :), but after compiling,
  58. the C code is much smaller.
  59.  
  60. In Basic, the Print statement gets converted to:
  61.    1. Make a string version of variable X.
  62.    2. Append this string X to the rest of the string (nothing in this case)
  63.    3. Print the string.
  64. In C, the code would be compiled as:
  65.    1. Insert the decimal value of x into the string
  66.    2. Print the string.
  67.  
  68. (this is just an example, so please don't jump on me if that isn't exact :)
  69.  
  70. The compiled Basic has one more thing to do, and that also happens to be
  71. the slowest step in the process. The loop instructions also have the same
  72. sorts of differences, as do large chunks of all Basic programs.
  73.  
  74. The more complex commands in Basic, and Amos especially, can blossom into
  75. large chunks of compiled code, and unless you use every available feature
  76. of the command every time you call it, there is bound to be some wastage
  77. in the compiled code (like the second step of the Print example), which
  78. could often be avoided when using C, and always avoided when using Asm.
  79. (assuming, of course, you know C or asm.... :)
  80.  
  81. {lecture mode=off}  :-)
  82.  
  83. Ok. Hope that helped........ (hope it didn't bore you witless)...... :))
  84.  
  85. Seeyall!
  86.  
  87.     / |\   /
  88.     \ | \ /
  89.     / |_/ \_
  90.  (Simon Champion)    <simonc@mcs.co.uk>
  91.  
  92. -------------------------------------------------------------------------------
  93. "Here speeking American Enlish well talking"  - Sign in Majorca shop.